//
//  LOLMainTabBarController.swift
//  MyLOLSwiftProject
//
//  Created by apple on 2016/12/2.
//  Copyright © 2016年 WangChen. All rights reserved.
//

import UIKit

class LOLMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置一些tabbar属性
        tabBar.isOpaque = true
        tabBar.tintColor = tab_t_color
        
        //添加Controller
        addChildrenVC()
        
    }

    //添加所有的子控制器
    private func addChildrenVC(){
        
        let recommendNaviVC = getNaviVC(vcName: "LOLRecommendController", title: "推荐", imageName: "btn_home")!
        let heroNaviVC = getNaviVC(vcName: "LOLHeroController", title: "英雄", imageName: "btn_hero")!
        let liveNaviVC = getNaviVC(vcName: "LOLLiveController", title: "直播", imageName: "btn_live")!
        let mineNaviVC = getNaviVC(vcName: "LOLMineController", title: "我的", imageName: "btn_user")!
        
        viewControllers = [recommendNaviVC,heroNaviVC,liveNaviVC,mineNaviVC]
        
    }
    
    
    //得到包装为Navi的子控制器
    private func getNaviVC(vcName: String,title: String,imageName: String) -> (LOLMainNavigationController?){
        
        let bundleName = Bundle.main.infoDictionary!["CFBundleName"] as! String
        let className = bundleName + "." + vcName
        
        guard let classType = NSClassFromString(className) as? UIViewController.Type else {
            return nil
        }
        
        let vc = classType.init()
        
        vc.tabBarItem.title = title
        vc.tabBarItem.image = UIImage(named: imageName + "_normal")
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        
        let naviVC = LOLMainNavigationController(rootViewController: vc)
        
        return naviVC
    }
    
    
    
    

}
